#include <iostream>
#include <QList>
#include <QString>

#include "zone.h"
using namespace std;
// The policy operations are here
//

/**
 * Adding a policy string to the jungle
 * @param polStr is the name of it 
 * return true if inserted successfully
 */
bool Zone::addPolicy(const QString &polStr,const QList<QString> &p_list){
   
    QString *temp_str;
    bool found = false;

    if((polStr.compare("deny_all")==0 || polStr.compare("allow_all")==0)& p_list.size()==0)
        return false;

    for(int i=0;i<4;i++){
        temp_str = new QString(VALID_POLICIES[i]);
        
        if (temp_str->compare(polStr)==0){
            found=true;
            delete temp_str;
            break;
        }
        delete temp_str;
        temp_str = 0;
        
    }

    if (!found)
        return false;

    Policy temp_policy;
    temp_policy.policy_name = polStr;
    
    //add the others
    if(p_list.size()!=0){
        for(int i=0;i<p_list.size();i++)
            temp_policy.person_list.append(p_list.at(i));
    }

    //add it at the end
    policy_list.append(temp_policy);

    return true;
}

/**
 * Gets info about zone's policy 
 * just to std
 */

bool Zone::listPolicy() {
    
    for(int i=0;i<policy_list.size();i++){
        
        cout <<"********************"<<endl;
        cout << "That is info for :"<<i <<endl;
        cout << "The policy name is : "<<policy_list.at(i).policy_name.toStdString() << endl;
        int tem_len = policy_list.at(i).person_list.size();
        for(int j=0;j<tem_len;j++)
            cout << "The person name is : "<<policy_list.at(i).person_list.at(j).toStdString()<<endl;

    }

    return true;
}

//Reset all policies
bool Zone::resetIt(){
    policy_list.clear();
    return true;
}

